package org.example.design.adapter;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import org.example.design.adapter.itf.OrderAdapterService;
import org.example.design.adapter.itf.impl.InsideOrderService;
import org.example.design.adapter.itf.impl.POPOrderAdapterServiceImpl;
import org.example.design.adapter.mq.MQAdapter;
import org.example.design.adapter.mq.OrderMq;
import org.example.design.adapter.mq.RebateInfo;
import org.example.design.adapter.mq.create_account;

import java.lang.reflect.InvocationTargetException;
import java.util.Date;
import java.util.HashMap;

/**
 * @Classname Test
 * @Description
 * @Date 2020/11/3 11:20 上午
 * @Created by xiangjd
 */
public class Test {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        create_account account = new create_account();
        account.setNumber("123");
        account.setAddress("成都市锦江区");
        account.setAccoutDate(DateUtil.date());
        account.setDesc("在校开户");

        HashMap<String, String> map = new HashMap<String, String>(16);
        map.put("userId", "number");
        map.put("bizId", "number");
        map.put("bizTime", "accoutDate");
        map.put("desc", "desc");

        RebateInfo info1 = MQAdapter.filter(account.toString(), map);
        System.out.println("适配前:" + account.toString());
        System.out.println("适配后：" + JSON.toJSONString(info1));


        System.out.println("");

        OrderMq orderMq = new OrderMq();
        orderMq.setUid("100001");
        orderMq.setSku("10928092093111123");
        orderMq.setOrderId("100000890193847111");
        orderMq.setCreateOrderTime(new Date());

        HashMap<String, String> link02 = new HashMap<String, String>();
        link02.put("userId", "uid");
        link02.put("bizId", "orderId");
        link02.put("bizTime", "createOrderTime");
        RebateInfo rebateInfo02 = MQAdapter.filter(orderMq.toString(), link02);

        System.out.println("mq.orderMq(适配前)" + orderMq.toString());
        System.out.println("mq.orderMq(适配后)" + JSON.toJSONString(rebateInfo02));


        System.out.println("");

        OrderAdapterService insideOrderService = new InsideOrderService();
        System.out.println("接口适配后(内部)" + insideOrderService.ifFirst("1001"));
        OrderAdapterService popOrderAdapterService = new POPOrderAdapterServiceImpl();
        System.out.println("接口适配后（第三方）" + popOrderAdapterService.ifFirst("1001"));



    }
}
